<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('待查明细列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li class="select-time">
                                <label>凭证日期：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginPzrq]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endPzrq]"/>
                            </li>
                            <li>
								代理银行：<select name="yhbm" >
									<option value="">所有银行</option>
									<option th:each="bk : ${yhlist}" th:text="${bk.yhmc}+'-'+${bk.skrzh}" th:value="${bk.yhbm}"></option>
								</select>
							</li>
                            <li>
                                <label style="width:80px" >待查流水号：</label>
                                <input type="text" name="dclsh"/>
                            </li>
                            <li>
                                <label style="width:80px">缴款人名称：</label>
                                <input type="text" name="jkr"/>
                            </li>
                            <li>
                                <label>待查金额：</label>
                                <input type="text" name="params[dfje]"/>
                            </li>
                           <li>
								待查状态：<select name="params[dczt]" >
									<option value="0">未确认</option>
									<option value="1">已确认未记账</option>
									<option value="2">已记账</option>
									<option value="3">已冲销</option>
									<option value="">所有</option>
								</select>
							</li>
                             
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success multiple disabled" onclick="autoaffirm()" shiro:hasPermission="system:dcjtmx:add">
                    <i class="fa fa-plus"></i> 自动角认
                </a>
                <a class="btn btn-primary multiple disabled" onclick="affirm()" shiro:hasPermission="system:dcjtmx:affirm">
                    <i class="fa fa-edit"></i> 手工确认
                </a>
                <a class="btn btn-danger multiple disabled" onclick="comfirm()" shiro:hasPermission="system:dcjtmx:comfirm">
                    <i class="fa fa-remove"></i>审核记账
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:dcjtmx:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table ">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var affirmreset = [[${@permission.hasPermi('system:dcjtmx:affirmreset')}]];
        var affirmcancel = [[${@permission.hasPermi('system:dcjtmx:affirmcancel')}]];
        var confirmcancel = [[${@permission.hasPermi('system:dcjtmx:confirmcancel')}]];
      
        var prefix = ctx + "system/dcjtmx";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "待查明细",
                showFooter: true,
                rememberSelected: true,
                columns: [{
                    checkbox: true
                },{
                    field: 'ywrq',
                    title: '业务日期'
                },
                {
                    field: 'pzrq',
                    title: '凭证日期'
                },
                {
                    field: 'dfje',
                    title: '待查金额'
                },
                {
                    field: 'remark',
                    title: '备注'
                },{
                    field: 'jkr',
                    title: '缴款人名称'
                },{
                    field: 'jkyhzh',
                    title: '缴款人账号'
                },
                {
                    field: 'jkyhmc',
                    title: '缴款人银行'
                },
                {
                    field: 'zy',
                    title: '摘要'
                },
                {
                    field: 'yhbm',
                    title: '专户银行编码'
                },
                {
                    field: 'yhmc',
                    title: '专户银行名称'
                },
                {
                    field: 'yhzh',
                    title: '专户银行账号'
                },
                {
                    field: 'pztxh',
                    title: '凭证头序号'
                },
                {
                    field: 'pzbh',
                    title: '凭证编号'
                }, 
                {
                    field: 'sfqr',
                    title: '是否确认'
                },
                {
                    field: 'sfsh',
                    title: '是否审核'
                }, 
               
                {
                    field: 'qrpztxh',
                    title: '确认凭证头序号'
                },
                {
                    field: 'qrlsh',
                    title: '确认流水号'
                },{
                    field: 'dclsh',
                    title: '待查流水号'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if (row.sfqr == '0') {
	                        actions.push('<a class="btn btn-success btn-xs ' + affirmreset + '" href="javascript:void(0)" onclick="resetaffirm(\'' + row.pztxh + '\',\''+ row.dclsh + '\')"><i class="fa fa-edit"></i>待查冲销</a> ');
                        }else if (row.sfqr == '1'){
                        	if (row.sfsh == '0'){
                        	   actions.push('<a class="btn btn-info btn-xs ' + affirmcancel + '" href="javascript:void(0)" onclick="listaffirm(\'' + row.qrlsh + '\')"><i class="fa fa-edit"></i>确认明细</a> ');
	                           actions.push('<a class="btn btn-danger btn-xs ' + affirmcancel + '" href="javascript:void(0)" onclick="cancelaffirm(\'' + row.qrlsh + '\')"><i class="fa fa-plus"></i>撤销确认</a> ');
                        	} else if (row.sfsh == '1'){
    	                      actions.push('<a class="btn btn-success btn-xs ' + confirmcancel + '" href="javascript:void(0)" onclick="jzconfirmcancel(\'' + row.qrlsh + '\')"><i class="fa fa-edit"></i>已记账撤销确认</a> ');	
    	                      actions.push('<a class="btn btn-info btn-xs ' + confirmcancel + '" href="javascript:void(0)" onclick="listaffirm(\'' + row.qrlsh + '\')"><i class="fa fa-edit"></i>确认明细</a> ');
    	                      actions.push('<a class="btn btn-info btn-xs ' + confirmcancel + '" href="javascript:void(0)" onclick="pzlist(\'' + row.qrpztxh + '\')"><i class="fa fa-plus"></i>查看凭证</a> ');
                        	}
                       }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        function affirm() {
			var ids = $.table.selectColumns("dclsh");
	    	if (ids.length == 0) {
				$.modal.alertWarning("请至少选择一条记录");
				return;
			}
	    	var sfqrs = $.table.selectColumns("sfqr");
	    	for (var i=0;i<sfqrs.length;i++){
	    		if (sfqrs[i]=='1'){
					$.modal.alertWarning("请选未确认的记录");
				    return;
	    		}
			}
	    	var dfjes = $("#bootstrap-table").bootstrapTable('getSelections');
	    	var zje=0;
	    	for (var i=0;i<dfjes.length;i++){
	    		var row=dfjes[i];
	    		zje=zje+Number(row['dfje']);
			}
		    var url = prefix + '/add/' + ids+'/'+zje;
		    $.modal.open("待查确认", url, '800', '540');
		}
        
        function listaffirm(qrlsh) {
        	$.modal.confirm("确认要显示查明明细数据吗?", function() {
        		var url = prefix + '/listdcqrmx/' + qrlsh
       		    $.modal.open("待查确认明细查看", url, '800', '540');
			});
		}
        
		
		function autoaffirm() {
			var rows =  $.table.selectColumns("dclsh");
			if (rows.length == 0) {
				$.modal.alertWarning("请至少选择一条记录");
				return;
			}
			$.modal.confirm("确认要自动确认选中的" + rows.length + "条数据吗?", function() {
				var url = table.options.removeUrl;
				var data = { "ids": rows.join() };
				$.operate.submit(prefix + "/autoaffirm", "post", "json", data);
			});
		}
		function comfirm() {
			var rows =  $.table.selectColumns("dclsh");
			if (rows.length == 0) {
				$.modal.alertWarning("请至少选择一条记录");
				return;
			}
			$.modal.confirm("确认要审核记账选中的" + rows.length + "条数据吗?", function() { 
				var data = { "ids": rows.join() };
				$.operate.submit(prefix + "/comfirm", "post", "json", data);
			});
		}
		function resetaffirm(pztxh,dclsh) {
			$.modal.confirm("确认要待查冲销选中的数据吗?", function() {
				var data = { "pztxh": pztxh,"dclsh": dclsh };
				$.operate.submit(prefix + "/affirmreset", "post", "json", data);
			});
		}
		
		function cancelaffirm(dclsh) {
			$.modal.confirm("确认要撤销确认选中的数据吗?", function() {
				var data = {"dclsh": dclsh};
				$.operate.submit(prefix + "/affirmcancel", "post", "json", data);
			});
		}
		function jzconfirmcancel(dclsh) {
			$.modal.confirm("确认要已记账撤销确认选中的数据吗?", function() {
				var data = { "dclsh": dclsh};
				$.operate.submit(prefix + "/confirmcancel", "post", "json", data);
			});
		}
		
		function pzlist(pztxh) {
		    var url = ctx + 'system/pzto/pzlist/' + pztxh;
		    $.modal.openFull("查看凭证", url, '800', '540');
		}
        
    </script>
</body>
</html>